class Task
  attr_reader :name
  attr_accessor :parent

  def initialize(name='default task')
    @name = name
  end
  def time_required()
    0.0 #the default time required is 0.0 seconds
  end
end

class CompositeTask < Task
  def initialize(name)
    super(name)
    @tasks = []
  end
  def add_task(task)
    @tasks << task
  end
  def remove_task(task)
    @tasks.remove(task)
  end
  def time_required()
    @tasks.inject(0) { |time, task| time += task.time_required() }
  end
end

class MathDiagram < Task
  def time_required()
    20
  end
end

class MathProblem < Task
  def time_required()
    50
  end
end

class MathHW < CompositeTask
  def initialize(name)
    super(name)
    add_task(MathDiagram.new('Math-diagrams'))
    add_task(MathProblem.new('Math-problem'))
  end
end

def main()
  math_hw = MathHW.new('Math-homework')
  puts(math_hw.time_required())
end

main()
